#include "common.h"

layout(location = TEXCOORD0)	in half2 	tc0;	// base
layout(location = TEXCOORD1)	in half2 	tc1;	// lmap
layout(location = TEXCOORD2)	in half2	tc2;	// hemi
layout(location = TEXCOORD3)	in half3	tc3;	// env
layout(location = COLOR0)		in half4	c0;
layout(location = COLOR1)		in half3	c1;

layout(location = COLOR0)		out half4	C;

uniform samplerCUBE 	s_env;

//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
void 	main	( )
{
	half4	t_base 	= tex2D		(s_base,tc0);
	half4	t_lmap 	= tex2D		(s_lmap,tc1);
	half4	t_env 	= texCUBE	(s_env,	tc3);

	// lighting
	half3 	l_base 	= t_lmap.rgb;				// base light-map
	half3	l_hemi 	= c0*p_hemi(tc2);			// hemi
	half3 	l_sun 	= c1*t_lmap.a;				// sun color
	half3	light	= L_ambient.rgb + l_base + l_sun + l_hemi;

	// final-color
	half3 	base 	= lerp		(t_env.rgb,t_base.rgb,t_base.a);
	half3	final 	= light*base*2;
	
	// out
	C	=  half4	(final.r,final.g,final.b,t_base.a*c0.a*c0.a);
}
